<template>
<!-- 搜索选择人物 -->
<view class="choice">
	<view class="choice_box">
		<view class="choice_sear">	
			<image class="sear_img" :src="photo_cdn + 'zpupload/static/zuzhi/sousuo.png'" mode="widthFix"></image>
			<input v-model="keywords"  confirm-type="search" @confirm="searchfun" class="sear_text" placeholder="搜索"></input>
		</view>
		<view class="choice_btn" @tap="searchfun">搜索</view>
	</view>
	
	<view class="choice_list" v-for="(item,index) in choice_list" @tap="toReturn(item)">
		<view class="flex ali-c">
			<image class="peimg" :src="photo_cdn + 'zpupload/static/zupu/seresult.png'"></image>
			<view class="pename">{{item.people_name}}</view>
		</view>		
		<view class="flex">
			<view v-if="item.parent_name" class="pefather">[父亲]</view>
			<view class="pefather">{{item.parent_name}}</view>
		</view>
	</view>
	
	<empty v-if="choice_list.length==0"></empty>
</view>	
</template>

<script>
	import {searchTree} from "@/utils/api/zupu.js";
	import config from "@/utils/config.js";
	let {staticurl,photo_cdn} = config.baseUrl;
	export default{
		data(){
			return{
				photo_cdn,
				keywords:'',
				family_id:0,
				choice_list:[]
			}
		},
		onLoad(option){
			this.family_id = option.family_id?option.family_id:0;
			uni.removeStorageSync('people_id')
		},
		methods:{
			//搜索
			searchfun(){
				if(!this.keywords){
					this.$api.msg("请输入名字")
					return false;
				}
				searchTree({
					family_id:this.family_id,
					keywords:this.keywords
				}).then((res)=>{
					if(res.code==1){
						this.choice_list = res.data;
					}
					this.$api.msg(res.msg)
				})
			},
			toReturn(item){
				uni.setStorageSync("people_id",item.people_id);
				uni.navigateBack();
				
			}
		}
	}
</script>

<style lang="scss">
	@import "./choice_hum.scss"
</style>